#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

int contains(int the_array[], int card, int size)
{
	int i;

	for (i = 0; i < size; i++) {
		if (the_array[i] == card) {
			return 1;
		}
	}

	return 0;
}

void test_fullDeckCount()
{
	int player;
	int card;
	int check_card;
	struct gameState state;
	int check_count = 0;
	int i;

	player = 0;
	check_card = feast;
	state.deckCount[player] = 500;

	/* Test One: card in deck */
	do {
		for (i = 0; i < state.deckCount[player]; i++) {
			card = (int)floor(Random() * 26);
			if (card == feast) {
				check_count++;
			}

			state.deck[player][i] = card;
		}
	} while (!contains(state.deck[player], feast, state.deckCount[player]));

	if (fullDeckCount(player, feast, &state) == check_count) {
		printf("Test One: PASS\n");
	} else {
		printf("Test Two: FAIL - did not count feasts in deck\n");
	}

	/* Test Two: card in hand and deck */
	state.handCount[player] = state.deckCount[player];

	do {
		for (i = 0; i < state.handCount[player]; i++) {
			card = (int)floor(Random() * 26);
			if (card == feast) {
				check_count++;
			}

			state.hand[player][i] = card;
		}
	} while (!contains(state.hand[player], feast, state.handCount[player]));

	if (fullDeckCount(player, feast, &state) == check_count) {
		printf("Test One: PASS\n");
	} else {
		printf("Test Two: FAIL - did not count feasts in hand\n");
	}

	/* Test Three: card in discard hand */
	state.discardCount[player] = state.deckCount[player];

	do {
		for (i = 0; i < state.discardCount[player]; i++) {
			card = (int)floor(Random() * 26);
			if (card == feast) {
				check_count++;
			}

			state.discard[player][i] = card;
		}
	} while (!contains(state.discard[player], feast, state.discardCount[player]));

	if (fullDeckCount(player, feast, &state) == check_count) {
		printf("Test One: PASS\n");
	} else {
		printf("Test Two: FAIL - did not count feasts in discard\n");
	}
}

int main(void)
{
	test_fullDeckCount();
	return EXIT_SUCCESS;
}